<?php header("Content-Type:text/html;charset=gb2312"); 

//签名函数
function createSign ($paramArr) {
     global $appSecret;
     $sign = $appSecret;
     ksort($paramArr);
     foreach ($paramArr as $key => $val) {
         if ($key != '' && $val != '') {
             $sign .= $key.$val;
         }
     }
     $sign.=$appSecret;
     $sign = strtoupper(md5($sign));
     return $sign;
}

//组参函数
function createStrParam ($paramArr) {
     $strParam = '';
     foreach ($paramArr as $key => $val) {
     if ($key != '' && $val != '') {
             $strParam .= $key.'='.urlencode($val).'&';
         }
     }
     return $strParam;
}

?><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>短信发送</title>
<style type="text/css">
/*自定义css*/
body{font-family:Georgia,仿宋_GB2312, Arial, Helvetica, sans-serif;}
table {margin:0 auto;width:468px;}
td{padding:1px;text-align:center;}
td span{font-size:14px;padding:1px;}
#m_,#n_{color:red;}
span,i{white-space:nowrap;text-overflow:ellipsis;overflow:hidden;display:block;}
i{width:320px;background:#e5f2fa;font-size:24px;font-weight:600;}
hr{PAGE-BREAK-AFTER:always;HEIGHT:0px;width:0px;margin:0;}
</style>
</head>
<body>
<script language="javascript"> 
var $=function(node){
return document.getElementById(node);
}
function $(objId){
return document.getElementById(objId);
}
function startRequest(Num) {
var queryString;
var ms=$("m").value.replace(/(^\s+)|(\s+$)/g, "");//去除前后的空格
var ns=$("n").value.replace(/(^\s+)|(\s+$)/g, "");//去除前后的空格
if(Num == 3 || Num == 0){
if (!ms.match(/^1[34578][\d]{9}$/)){
$('m').style.borderColor='red';
$("m_").innerHTML="请输入正确手机号！";
return false;
}else{
$('m').style.borderColor='green';
$("m_").innerHTML="OK！";
}
}
if(Num == 4 || Num == 0){
if (!ns.match(/^[0-9]{6}$/)){
//if($("n").value == ""){
$('n').style.borderColor='red';
$("n_").innerHTML="请输入6位数字验证码！";
return false;
}else{
$('n').style.borderColor='green';
$("n_").innerHTML="OK！";
}
}
if(Num == "0"){
//$("sub").submit();
//return false;
}
}
</script>
<?php

$mm=$_POST['m'];
$nn=$_POST['n'];
$randkey= rand(111000,999888);

if(!$mm){
}else{

//修改以下参数为你的参数（正确修改才可以正常使用）
//**********************************************************
//以下俩项目：https://www.alidayu.com/center/application/list点击对应项目后查看
$appKey = '232788888';  
$appSecret = '12345678900000000';
//在这个页面查看短信模板：https://www.alidayu.com/center/tpl/list/code
$template_code = 'SMS_2505450';
//在这个页面查看短信签名：https://www.alidayu.com/center/sign/list/code
$sinname= '身份验证'; //
$product= '微信公众号绑定身份验证';
//**********************************************************


//以下不用管
$sinname= iconv('GB2312', 'UTF-8', $sinname);
$product= iconv('GB2312', 'UTF-8', $product);
$sinnames= urlencode($sinname);
$products= urlencode('{"code":"'.$randkey.'","product":"'.$product.'"}');
$sinnames= $sinname;
$products= '{"code":"'.$nn.'","product":"'.$product.'"}';

//参数数组
$paramArr = array(
     'app_key' => $appKey,
     'method' => 'alibaba.aliqin.fc.sms.num.send',
     'format' => 'xml',
     'v' => '2.0',
     'sms_type' => 'normal',
     'sign_method'=>'md5',
     'timestamp' => date('Y-m-d H:i:s'),
     'extend' => ''.$randkey.'',
     'rec_num' => ''.$mm.'',
     'sms_free_sign_name' => ''.$sinnames.'',
     'sms_param' => ''.$products.'',
     'sms_template_code' => ''.$template_code.''
);

//生成签名
$sign = createSign($paramArr);

//组织参数
$strParam = createStrParam($paramArr);
$strParam .= 'sign='.$sign;

//访问服务
$url = 'http://gw.api.taobao.com/router/rest?'.$strParam; //沙箱环境调用地址
$result = file_get_contents($url);
//$result = json_decode($result);
echo "<br>'.$result.'<br>";
//print_r($result);
}

?>
<table border="0" cellpadding="0">
<form id="form" name="form" method="post" action="" onsubmit="return startRequest(0);">
<tr>
<td style="width:120px;">
手机号：
</td>
<td>
<input name="m" type="text" id="m" style="width:100%;" onBlur="startRequest(3)" /><span id="m_"></span>
</td>
</tr>
<tr>
<td style="width:120px;">
验证码：
</td>
<td>
<input name="n" type="text" id="n" style="width:100%;" onBlur="startRequest(4)" value="<?php echo $randkey; ?>" /><span id="n_"></span>
</td>
</tr>
<tr>
<td colspan="2" bgcolor="#FFFFFF">
<input type="submit" name="Submit3" value=" 发送短信 " />
</td>
</tr>
</form>
</table>
<!--  各步教程见：https://doc.alidayu.com/doc2/index.htm?spm=a3142.7629065.1.27.IH6rX2   -->
</body>
</html>